package com.aizhixin.lab.post.server;

import com.aizhixin.lab.post.domain.SkillColorDomain;
import com.aizhixin.lab.post.entity.PostSkill;
import com.aizhixin.lab.post.entity.SkillColor;
import com.aizhixin.lab.post.repository.SkillColorRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Slf4j
@Service
@Transactional
public class SkillColorService {
    @Autowired
    private SkillColorRepository colorRepository;

    public SkillColor save(SkillColor skillColor){
        return colorRepository.save(skillColor);
    }
    public List<SkillColor> save(List<SkillColor> colorList){
        return colorRepository.save(colorList);
    }
    public List<SkillColor> findAll(){
       return colorRepository.findAll();
    }
    public List<SkillColorDomain> findAllDomain(){
        List<SkillColorDomain> colorDomainList=new ArrayList<>();
        List<SkillColor> skillColorList = colorRepository.findAll();
        for (SkillColor skillColor:skillColorList){
            SkillColorDomain domain = new SkillColorDomain();
            BeanUtils.copyProperties(skillColor,domain);
            colorDomainList.add(domain);
        }
        return colorDomainList;
    }
    public Integer delete(String id){
      return  colorRepository.deleteById(id);
    }

    public SkillColor saveDomain(SkillColorDomain domain){
        SkillColor skillColor = new SkillColor();
        domain.setId(UUID.randomUUID().toString());
        BeanUtils.copyProperties(domain,skillColor);

       return colorRepository.save(skillColor);
    }
    public SkillColor updateDomain(SkillColorDomain domain){
        SkillColor skillColor = new SkillColor();
        BeanUtils.copyProperties(domain,skillColor);
        return colorRepository.save(skillColor);
    }
}
